package cs275.ants.agent;

import java.util.logging.Logger;

import junit.framework.TestCase;
import cs275.ants.graph.Maze;
import cs275.ants.graph.MazeCell;
import cs275.ants.graph.MazeGenerator;
import cs275.ants.graph.MazeCell.Wall;
import cs275.ants.graph.antgraph.AntGraph;
import cs275.ants.graph.antgraph.AntGraphEdge;
import cs275.ants.graph.base.GraphEdge;

public class AntMazeIntegrationTest extends TestCase {

	private static final Logger logger = Logger.getLogger(AntMazeIntegrationTest.class.getName());
	private Maze maze;
	private AntGraph graph;

	@Override
	protected void setUp() throws Exception {
//		Logger antLogger = Logger.getLogger(Ant.class.getName());
//		antLogger.setLevel(Level.FINEST);
		
		MazeCell northWest = new MazeCell(0, 0, Wall.UP, Wall.LEFT, Wall.RIGHT, Wall.NONE);
		MazeCell north = new MazeCell(0, 1, Wall.UP, Wall.LEFT, Wall.RIGHT, Wall.NONE);
		MazeCell northEast = new MazeCell(0, 2, Wall.UP, Wall.LEFT, Wall.RIGHT, Wall.NONE);

		MazeCell west = new MazeCell(1, 0, Wall.NONE, Wall.LEFT, Wall.NONE, Wall.NONE);
		MazeCell center = new MazeCell(1, 1, Wall.NONE, Wall.NONE, Wall.NONE, Wall.NONE);
		MazeCell east = new MazeCell(1, 2, Wall.NONE, Wall.RIGHT, Wall.NONE, Wall.NONE);
		
		MazeCell southWest = new MazeCell(2, 0, Wall.NONE, Wall.LEFT, Wall.RIGHT, Wall.DOWN);
		MazeCell south = new MazeCell(2, 1, Wall.NONE, Wall.LEFT, Wall.RIGHT, Wall.DOWN);
		MazeCell southEast = new MazeCell(2, 2, Wall.NONE, Wall.LEFT, Wall.RIGHT, Wall.DOWN);
		
		// SouthEast will have food.
		southEast.setHasFood(true);
		
		MazeCell[][] cells = { 
				{ northWest, north, northEast }, 
				{ west, center, east },
				{ southWest, south, southEast } 
		};
		
		maze = new Maze(3, 3, cells);
		graph = maze.getGraph();
	}
	
	/**
	 * Not really asserting much here.  This is just testing ground.
	 */
	public void testAntInMaze() {
		AntManager manager = AntManager.withAnts(10, graph, graph.getVertex(0, 0));
//		for (int i = 0; i < 1000; i++) {
		for (int i = 0; i < 1; i++) {
			if(i%1000 == 0) {
				manager.addAnts(10, graph, graph.getVertex(0, 0));
			}
			manager.moveAllAnts();
			for(GraphEdge edge : graph.getAllEdges()) {
				AntGraphEdge antEdge = (AntGraphEdge) edge;
				antEdge.updatePheromone();
			}
			logger.info(String.format("%d: %s", i, graph.getAllEdges()));
		}
	}
		
//	public void testWithGraphics() {
//		Resources resources = new Resources();
//		CharacterGenerator characterGenerator = new CharacterGenerator(
//				resources);
//		Graphics scene = new Graphics(new FakeMazeGenerator(maze), characterGenerator, new NoOpParticleGenerator());
//		scene.setConfigShowMode(ConfigShowMode.AlwaysShow);
//		scene.start();
//	}
	
	private static class FakeMazeGenerator extends MazeGenerator {
		private Maze maze;
		public FakeMazeGenerator(Maze maze) {
			this.maze = maze;
		}

		@Override
		public Maze generate(int cols, int rows) {
			return maze;
		}
	}
}
